require 'gadgets/combobox'
module EventEditor
  module Commands
    class Goto
      def self.show(base, model, edit_command = [], options = {}, &func)
       @dialog = Gtk::Dialog.new("Goto",
               base,
               Gtk::Dialog::MODAL,
               ["OK", Gtk::Dialog::RESPONSE_OK],
               ["Cancel", Gtk::Dialog::RESPONSE_CANCEL]
               )
               

        @dialog.vbox.add(self.create_panel)
        @dialog.vbox.show_all

        self.load(edit_command)
        
        @dialog.run do |response|
          if response == Gtk::Dialog::RESPONSE_OK
            func.call(self.command)
          end
        end
        @dialog.destroy
      end
      
      def self.create_panel
        ## Create document
        hbox = Gtk::HBox.new
        @input = Gtk::SpinButton.new(0, 999, 1)
        hbox.add(Gtk::Label.new('Goto Label No:'))
        hbox.add(@input)
        return hbox
      end

      def self.load(edit_command)
        unless edit_command.empty?
          @input.value = edit_command[1]
        end
      end

      def self.command
        return ['goto', @input.value.floor]
      end

      def self.command_to_s(model, args, margin = "")
        s = "Goto: #{args[1]}"
        return s
      end
    end
  end
end